<%--
  Created by IntelliJ IDEA.
  User: yoka24443
  Date: 2018-4-8
  Time: 22:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.sql.*" contentType="text/html;charset=UTF-8" language="java" %>
<%
    String studentNO = "",
            realName = "",
            className = "",
            age = "",
            address = "",
            tel = "",
            wechat = "",
            qq="";
    Connection conn = null;
    Statement statement = null;
    ResultSet resultSet = null;
    try {
        //1.加载驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.驱动管理器获取数据库链接
        conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/school?user=root&password=&useUnicode=true&characterEncoding=utf8");
        //3.获取statement，执行sql
        statement = conn.createStatement();

        studentNO = request.getParameter("studentNO");

        if(studentNO != null && studentNO.trim().length() > 0) {
            String sql = String.format("select * from student where studentNO = '%s'", studentNO);

            //4.执行sql返回结果集并解析
            resultSet = statement.executeQuery(sql);

            if(resultSet.next()) {
                studentNO = studentNO.trim();
                realName = resultSet.getString("realName").trim();
                className = resultSet.getString("className").trim();
                age = String.valueOf(resultSet.getInt("age")).trim();
                tel = resultSet.getString("tel").trim();
                address = resultSet.getString("address").trim();
                wechat = resultSet.getString("wechat").trim();
                qq = resultSet.getString("qq").trim();
            }
        }
    } catch (ClassNotFoundException e) {
        out.println("连接数据库失败！");
        e.printStackTrace();
    } catch (SQLException e) {
        out.println("SQL执行出错！");
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if(resultSet != null) {
                resultSet.close();
            }
            if (statement != null) {
                statement.close();
            }
            if(conn != null) {
                conn.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
%>
<html>
<head>
    <title>修改学生信息</title>
</head>
<body>
    <form action="modifyStudent.jsp" method="post">
        <a href="StudentList.jsp">返回</a>
        <h3>修改学生信息</h3>
        <table>
            <tr>
                <td>学号：</td>
                <td><%=studentNO%></td>
                <input id="hid_studentNO" name="studentNO" type="hidden" value="<%=studentNO%>"/>
            </tr>
            <tr>
                <td>姓名：</td>
                <td><input id="txt_realName" name="realName" type="text" value="<%=realName%>"/></td>
            </tr>
            <tr>
                <td>班级名称：</td>
                <td><input id="txt_className" name="className" type="text" value="<%=className%>"/></td>
            </tr>
            <tr>
                <td>年龄：</td>
                <td><input id="txt_age" name="age" type="text" value="<%=age%>"/></td>
            </tr>
            <tr>
                <td>电话：</td>
                <td><input id="txt_tel" name="tel" type="text" value="<%=tel%>"/></td>
            </tr>
            <tr>
                <td>地址：</td>
                <td><input id="txt_address" name="address" type="text" value="<%=address%>"/></td>
            </tr>
            <tr>
                <td>微信：</td>
                <td><input id="txt_wechat" name="wechat" type="text" value="<%=wechat%>"/></td>
            </tr>
            <tr>
                <td>QQ：</td>
                <td><input id="txt_qq" name="qq" type="text" value="<%=qq%>"/></td>
            </tr>
            <tfoot>
                <tr>
                    <td colspan="2">
                        <input type="submit" id="btn_submit" value="修改"/>
                        <input type="button" onclick="javascript:window.location.href='./StudentList.jsp';return false;" id="btn_back" value="返回列表"/>
                    </td>
                </tr>
            </tfoot>
        </table>
    </form>
</body>
</html>
